﻿using System;
using System.Data;

namespace Codeflows.Tracking.BuiltIn
{
    class DataRow
    {
        public Guid CodeflowId { get; private set; }
		public string CodeflowType { get; private set; }
        public string FriendlyName { get; private set; }
        public int Status { get; private set; }
        public DateTime? TimeToWakup { get; private set; }        
        public DateTime LockedUntilUtc { get; set; }
        public Guid DispatcherId { get; set; }        
        public string ActionName { get; private set; }        
        public int DispatchAttemptsCount { get; private set; }
        public string ArgumentsJson { get; private set; }
        public DateTime StartedAtUtc { get; private set; }        
        public byte[] SerializedArguments { get; private set; }        
        public DateTime CreatedOnUtc { get; private set; }
        public DateTime ModifiedOnUtc { get; private set; }        

        public DataRow(IDataRecord record)
        {
            CodeflowId = record.GetGuid(0);
        	CodeflowType = record.GetString(1);
            FriendlyName = record.GetString(2);
            Status = record.GetInt32(3);
            TimeToWakup = record.IsDBNull(4) ? default(DateTime?) : record.GetDateTime(4);
            LockedUntilUtc = record.GetDateTime(5);
            DispatcherId = record.IsDBNull(6) ? default(Guid) : record.GetGuid(6);
            ActionName =  record.IsDBNull(7) ? default(string) : record.GetString(7);
            DispatchAttemptsCount = record.IsDBNull(8) ? default(int) : record.GetInt32(8);
            ArgumentsJson = record.IsDBNull(9) ? default(string) : record.GetString(9);
            StartedAtUtc =  record.IsDBNull(10) ? default(DateTime) : record.GetDateTime(10);
            SerializedArguments = record.IsDBNull(11) ? default(byte[]) : record.GetByteArray(11);                                    
            CreatedOnUtc = record.GetDateTime(12);
            ModifiedOnUtc = record.GetDateTime(13);            
        }
    }
}